﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Xml;

public partial class friends : System.Web.UI.Page
{
    protected string userName;
    protected void Page_Load(object sender, EventArgs e)
    {
        userName = User.Identity.Name;
        DatabaseSqlDataSource1.SelectParameters.Add(new Parameter("currUser", TypeCode.String, userName));
        DatabaseSqlDataSource2.SelectParameters.Add(new Parameter("currUser", TypeCode.String, userName));
        DatabaseSqlDataSource2.SelectParameters.Add(new Parameter("currFriend", TypeCode.String, ""));

        //GridViewRowCollection gr = GridView1.Rows;
        //IEnumerator iter = gr.GetEnumerator();
        //iter.MoveNext();
        //GridViewRow temp = (GridViewRow)iter.Current;
        //test.Text = temp.Cells[1].Text;


        //For every friend
       for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            DatabaseSqlDataSource2.SelectParameters.Clear();
            DatabaseSqlDataSource2.SelectParameters.Add(new Parameter("currFriend", TypeCode.String, GridView1.Rows[i].Cells[0].Text));
            DataSourceSelectArguments dssa = new DataSourceSelectArguments();
            dssa.MaximumRows = 10;
            dssa.AddSupportedCapabilities(DataSourceCapabilities.Page);
            DataView dv = (DataView)DatabaseSqlDataSource2.Select(dssa);
            GridView2.DataSource = dv;
            GridView2.DataBind();

            string picURL = getPicURL((GridView1.Rows[i].Cells[0].Text).Trim());

            Label1.Text += "<div id=‘userContainer’ style='margin: 5px; border: solid 1px #000;'> <div id=‘userHeader’ style='margin: 8px 8px 8px 10px; font-size: 1.4em; border-bottom: dashed 1px #000; height: 30px;'><p class=‘user’ style='font-weight: bold; float: left'>" + GridView1.Rows[i].Cells[0].Text + "'s feeds</p><p class=‘sort’ style='font-weight: lighter; text-align: right;'><img class=‘img’ style='border: none' src=Images/rss.gif></p></div><div id=‘userPic’ style='width: 180px; text-align: center; float: left; font-size: 1.4em; margin-left: 10px;'><p>" + GridView1.Rows[i].Cells[0].Text + "</p><img class=‘userPic’ src='" + picURL + "' alt='Picture' style='border: none' /></div><div id=‘sortFeeds’ style='margin: 8px 8px 8px 230px;'>"; 
           //For every friend's feed
            for (int j = 0; j < GridView2.Rows.Count; j++)
            {

                Label1.Text += "<p class=‘title’ style='font-size: 1em;'>" + GridView2.Rows[j].Cells[1].Text + " <span class='feed'>via " + GridView2.Rows[j].Cells[0].Text + " </span></p>";
                
                
            }

            Label1.Text += "</div><div id=‘userFoot’ style='clear: both; font-size: 1em; text-align: right; margin: 8px;'><p></a></p></div></div></ br></ br>";
        }
    }

    private string getPicURL(string userName)
    {
        string ret = "";

        sdsFindPic.SelectParameters.Clear();
        sdsFindPic.SelectParameters.Add(new Parameter("currUser", TypeCode.String, userName));
        DataSourceSelectArguments dssa = new DataSourceSelectArguments();
        dssa.MaximumRows = 10;
        dssa.AddSupportedCapabilities(DataSourceCapabilities.Page);
        DataView dv2 = (DataView)sdsFindPic.Select(dssa);

        if (dv2.Count > 0)
        {
            ret += dv2[0].Row[0].ToString();
        }
        else
        {

        }

        return ret;

    }


    protected void showFriendFeed_Click(object sender, EventArgs e)
    {
    }


}
         